# def func1():
#     print('in func1')
#     func2()
#
# def func2():
#     print('in func1')
#
#
# if __name__ == '__main__':
#     func1()
#关键字
#参数的形式是arg是位置参数
#key=all,关键字参数
#必须一一对应

from random import randint,choice
def exam():
    '出题用于做打'
    #生成两个数字，并排列
    nums = [randint(1, 100) for i in range(2)]
    nums.sort(reverse=True)
    #加减法字符取一
    op = choice('+-')
    #算出答案：

    if op == '+':
        result = nums[0] + nums[1]
    else:
        result = nums[0] - nums[1]
    #用户作出判断：
    prompt = '%s %s %s=' % (nums[0], op, nums[1])
    c = 0

    while c < 3:
        try:
            answer = int(input(prompt))
        except:
            print()
            continue

        if answer == result:
            print('恭喜你，答对了！')
            break
        print('不对哦')
        c += 1
    print('%s %s' % (prompt, result))

def show_menu():
    '用于程序的入口函数'
    while 1:
        exam()
        try:
            yn = input('continue(y/n):').strip()[0]
        except ImportError:
            continue
        except (KeyboardInterrupt, EOFError):
            yn = 'n'

        if yn in 'nN':
            print('\nBye')
            break

if __name__ == '__main__':
    show_menu()








